package com.hspedu.generic;

import java.util.*;

/**
 * @author LiuJinTao
 * @className GenericExercise
 * @date 2024/06/15 1:39
 * @description TODO
 */
public class GenericExercise {
    public static void main(String[] args) {
        HashSet<Student> set = new HashSet<>();
        set.add(new Student("join", 12));
        set.add(new Student("smith", 13));
        set.add(new Student("jack", 14));

        HashMap<String, Student> map = new HashMap<>();
        for (Student student : set) {
            map.put(student.getName(), student);
            System.out.println(student);
        }

        Set<Map.Entry<String, Student>> entries = map.entrySet();
        Iterator<Map.Entry<String, Student>> iterator1 = entries.iterator();
        while (iterator1.hasNext()) {
            Map.Entry<String, Student> next = iterator1.next();
            System.out.println(next.getKey() + "-" + next.getValue());
        }

    }
}

class Student {

    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}